package com.qdlc.p2p.common.util;

import java.util.Map;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.WebApplicationContext;

/**
 * 工具类-spring bean
 * @author linya 2016-01-25
 */
public class BeanUtil {
	private static WebApplicationContext ctx = ContextLoader.getCurrentWebApplicationContext();

	/**
	 * 根据bean名称获取
	 * 
	 * @param name
	 * @return
	 */
	public static Object getBean(String name) {
		return ctx.getBean(name);
	}
	
	public static ApplicationContext getApplicationContext(){
		return ctx;
	}
	
	public static <T> Map<String, T> getBeansOfType(Class<T> type){
		return ctx.getBeansOfType(type);
	}
	
	public static <T> T getBean(Class<T> requiredType){
		return ctx.getBean(requiredType);
	}
	
}
